import { Input } from "ant-design-vue";
import { computed, h, onMounted, Ref } from "vue";

export const useTestLowCode = (pageRenderRef: Ref<any>) => {
  const CompanyOptions = [
    { value: 1, label: "江苏恒瑞医药股份有限公司", version: "1.0.0" },
    { value: 2, label: "江苏中天科技股份有限公司", version: "2.0.0" },
    { value: 3, label: "江苏苏宁易购集团股份有限公司", version: "3.0.0" },
    { value: 4, label: "江苏沙钢集团有限公司", version: "4.0.0" },
    { value: 5, label: "江苏阳光集团有限公司", version: "5.0.0" },
    { value: 6, label: "江苏洋河酒厂股份有限公司", version: "6.0.0" },
    { value: 7, label: "徐工集团工程机械股份有限公司", version: "7.0.0" },
    { value: 8, label: "江苏亨通光电股份有限公司", version: "8.0.0" },
    { value: 9, label: "江苏南瑞集团公司", version: "9.0.0" },
    {
      value: 10,
      label: "江苏金通灵流体机械科技股份有限公司",
      version: "10.0.0",
    },
  ];
  let afterGetSchemas = (setSchemas: any) => {
    setSchemas(
      new Map<string, any>([
        [
          "importVersion",
          ({ formModel }: any) => {
            return {
              disabled: computed(
                () => !!formModel.supplierCustomerEnterpriseNo
              ),
            };
          },
        ],
        [
          "supplierCustomerEnterpriseNo",
          ({ formModel }: any) => {
            return {
              options: CompanyOptions,
              onChange: (value: any) => {
                formModel.importVersion = CompanyOptions.find(
                  (item: any) => item.value === value
                )?.version;
              },
            };
          },
        ],
        [
          "employeeNo",
          ({ formModel }: any) => {
            return h(
              "span",
              {
                style: "color: red",
              },
              "外部改变样式"
            );
          },
        ],
        [
          "sendNo",
          ({ formModel, schema }: any) => {
            return h(Input, {
              modelValue: formModel["sendNo"],
              onChange: (e: any) => {
                formModel["sendNo"] = e.target.value;
                formModel.importVersion = e.target.value;
              },
            });
          },
        ],
      ])
    );
  };
  let afterGetTables = (setColumns: any) => {
    // 存在多个表格，使用setColumns key 区分
    setColumns(
      "TESTBODY",
      new Map([
        [
          "createTime",
          ({ text, record }: any) => {
            return "2025-05-05 05:05:05";
          },
        ],
      ])
    );
    // setDataSource("TESTBODY",[
    //   {
    //     key: "1",
    //     name: "胡彦斌",
    //     age: 32,
    //     address: "西湖区湖底公园1号",
    //     createTime:1749125099031
    //   },
    //   {
    //     key: "2",
    //     name: "胡彦祖",
    //     age: 42,
    //     address: "西湖区湖底公园1号",
    //     createTime:1749125119108
    //   },
    // ])
  };

  return {
    afterGetSchemas,
    afterGetTables,
  };
};
